using System;

class Lift{
    private ILiftStatus curStatus;  // 一个 ConcreteState 的实例

    private OpenningStatus open_status = new OpenningStatus();
    private ClosingStatus close_status = new ClosingStatus();
    private MovingStatus move_status = new MovingStatus();
    private StopingStatus stop_status = new StopingStatus();

    public Lift(ILiftStatus initial_status=null){
        if(initial_status == null){
            // Console.WriteLine("默认初始化为 ClosingStatus");
            initial_status = close_status;
        }
        curStatus = initial_status;
    }

    public void open_door(){
        if(curStatus.check_open_door()){  // 状态监测
            Console.WriteLine("开门");
            curStatus = open_status;  // 状态更新
        }
    }
    public void close_door(){
        if(curStatus.check_close_door()){
            Console.WriteLine("关门");
            curStatus = close_status;
        }
    }
    public void move(){
        if(curStatus.check_move()){
            Console.WriteLine("运行");
            curStatus = move_status;
        }
    }
    public void stop(){
        if(curStatus.check_stop()){
            Console.WriteLine("停止");
            curStatus = stop_status;
        }
    }
}

interface ILiftStatus{
    bool check_open_door();
    bool check_close_door();
    bool check_move();
    bool check_stop();
}

class OpenningStatus: ILiftStatus{
    public bool check_open_door(){ Console.WriteLine("不能执行open_door");  return false; }
    public bool check_close_door(){ return true; }
    public bool check_move(){ Console.WriteLine("不能执行move");  return false; }
    public bool check_stop(){ Console.WriteLine("不能执行stop");  return false; }
}

class ClosingStatus: ILiftStatus{
    public bool check_open_door(){ return true; }
    public bool check_close_door(){ Console.WriteLine("不能执行close_door");  return false; }
    public bool check_move(){ return true; }
    public bool check_stop(){ return true; }
}

class MovingStatus: ILiftStatus{
    public bool check_open_door(){ Console.WriteLine("不能执行open_door");  return false; }
    public bool check_close_door(){ Console.WriteLine("不能执行close_door");  return false; }
    public bool check_move(){ Console.WriteLine("不能执行move");  return false; }
    public bool check_stop(){ return true; }
}

class StopingStatus: ILiftStatus{
    public bool check_open_door(){ return true; }
    public bool check_close_door(){ Console.WriteLine("不能执行close_door");  return false; }
    public bool check_move(){ return true; }
    public bool check_stop(){ Console.WriteLine("不能执行stop");  return false; }
}

class Demo_Status{
    public static void Main(){
        var lift = new Lift();

        lift.open_door();
        lift.move();
        lift.stop();
        lift.close_door();
    }
}
